<?php
namespace Common\Model;
use Common\Model\BaseModel;
use Think\Model;

/**
 * Class AnnounceModel
 * @package Common\Model
 * 公告模型
 */
class AnnounceModel extends BaseModel {
    public $pix = "";
    public $fieldsStr = '*';
    public $orderStr = 'createtime asc';

    public function addObj($post, $f_title='id'){
        //判重
        $data[$f_title] = array("eq", $post[$f_title]);
        $one = $this->where($data)->find();
        if(!$one){
            //如果没有记录，就添加
            foreach($post as $k=>$v){
                $data[$k] = $v;
            }
            $data['createtime'] = getNowTime();
            if(!isset($data['start_time']))
                $data['start_time'] = getNowTime();
            if(!isset($data['end_time']))
                $data['end_time'] = getNowTime();
            return $this->add($data);
        }else{
            //反之更新
            foreach($post as $k=>$v){
                $one[$k] = $v;
            }
            return $this->save($one);
        }
    }

}